package com.gitee.feizns.explore.data_structure.tree.bs.mid;

/**
 * @author feizns
 * @since 2020/3/19
 */
public class CheckSubTree {

    public static void main(String[] args) {

    }

    public static boolean checkSubTree(TreeNode t1, TreeNode t2) {
        return equals(t1, t2) || checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2);
    }

    private static boolean equals(TreeNode t1, TreeNode t2) {
        if ( t1 == t2 )
            return true;
        else if ( t1 == null || t2 == null )
            return false;
        else if ( t1.val == t2.val )
            return equals(t1.left, t2.left) && equals(t1.right, t2.right);
        return false;
    }

}
